﻿
@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini-v2/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini-v2/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">角色名</label>
            <div class="layui-input-inline">
                <input type="text" name="DepartmentRoleName" lay-verify="required" lay-reqtext="员工名不能为空" placeholder="请输入员工名" value="@ViewBag.DepartmentRoleName" class="layui-input" disabled="">
                @*<tip>填写自己管理账号的名称。</tip>*@
            </div>
        </div>

        @*<div class="layui-form-item">
            <label class="layui-form-label">权限</label>
            <div class="layui-input-block">
                @{ foreach (var list in ViewBag.data)
                    {
                        if (list.IsCheck == true)
                        {
                            <input type="checkbox" name="like" lay-skin="primary" title="@list.MenusName" checked="" value="@list.MenusId">
                        }
                        else
                        {
                            <input type="checkbox" name="like" lay-skin="primary" title="@list.MenusName" value="@list.MenusId">
                        }
                    }
                }
                @*<input type="checkbox" name="like1[write]" lay-skin="primary" title="写作" checked="">
                <input type="checkbox" name="like1[read]" lay-skin="primary" title="阅读">
                <input type="checkbox" name="like1[game]" lay-skin="primary" title="游戏" disabled="">
            </div>
        </div>*@


        <div class="layui-form-item">
            <label class="layui-form-label required">@ViewBag.data[0].title</label>
            <div class="layui-input-block">
                <div id="test12" class="demo-tree-more"></div>
            </div>
            
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>

    <script src="/layuimini-v2/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <script src="/layuimini-v2/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
        layui.use(['form', 'tableSelect', 'table','tree'], function () {
        var form = layui.form,
            layer = layui.layer,
            table = layui.table,
            tableSelect = layui.tableSelect,
            //layedit = layui.layedit,
            tree = layui.tree,
            //util = layui.util,
                $ = layui.$;
            var data2;
            var d = "";

            var data1 = $.ajax({
					url: "@Url.Action("GetListMenus")",
                    type: "get",
                    async:false,
                    data: { "id":@ViewBag.id },
					success: function (da) {
                        data2 = da;
						//layer.msg(da.msg)

					},
            })
            console.log("----");
            console.log(data2);
            console.log("----");

           

            //基本演示
            tree.render({
                elem: '#test12'
                , data: data2
                , showCheckbox: true  //是否显示复选框
                , id: 'demoId1'
                , isJump: true //是否允许点击节点时弹出新窗口跳转
                , click: function (obj) {
                    var data = obj.data;  //获取当前点击的节点数据
                    //layer.msg('状态：' + obj.state + '<br>节点数据：' + JSON.stringify(data));
                }
            });

        tableSelect.render({
            elem: '#demo2',
            checkedKey: 'id',
            searchKey: 'DepartmentRoleName',
            height: '200',  //自定义高度
            width: '10',  //自定义宽度
            table: {
                url: '@Url.Action("GettableSelectStaffList")',
                limits: [6, 10, 20, 30, 50, 100],
                limit: 6,
                cols: [[
                    { type: 'radio' },
                    @*{ field: 'Item1', title: 'ID'},*@
                    { field: 'Item2',title: '角色名' }
                ]]
            },
            done: function (elem, data) {
                var NEWJSON = []
                layui.each(data.data, function (index, item) {
                    NEWJSON.push(item.Item1)
                })
                elem.val(NEWJSON.join(","))
            }
        })

        //监听提交
            form.on('submit(saveBtn)', function (data) {
                //var data = data.field;
                var checkedData = tree.getChecked('demoId1'); //获取选中节点的数据
                for (i = 0; i < checkedData.length; i++) {
                    d = d + checkedData[i].id + ",";
                    if (checkedData[i].children.length > 0) {
                        for (j = 0; j < checkedData[i].children.length; j++) {
                            d = d + checkedData[i].children[j].id + ",";
                        }
                    }
                }
                d = d.slice(0, d.length - 1);
                console.log(d);

            var index = layer.alert("确定修改吗？", {
                title: '确认信息'
            }, function () {

                $.ajax({
					url: "@Url.Action("FenDepartmentRole")",
                    type: "post",
                    data: { "Id":@ViewBag.id , "like": d, 'DepartmentRoleName': data.field.DepartmentRoleName },
					success: function (da) {
						console.log(da)
						layer.msg(da.msg)

					},
				})

                // 关闭弹出层
                layer.close(index);

                var iframeIndex = parent.layer.getFrameIndex(window.name);
                parent.location.reload();
                parent.layer.close(iframeIndex);

            });

            return false;
        });

    });
    </script>
</body>
</html>